package com.wman.mvvm;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.TextView;

import com.wman.sheep.common.utils.TLog;

/**
 * @ProjectName: wman
 * @Package: com.wman.mvvm
 * @ClassName: ViewBinder
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2019/11/11 15:25
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/11/11 15:25
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class ViewBinder {
    void bind(final TextView textView, final ViewModel.TextAttr text) {
        textView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.equals(text.getText())) {
                    text.setText(editable.toString());
                }
            }
        });

        text.setOnChangeListener(new ViewModel.TextAttr.OnChangeListener() {
            @Override
            public void onChange(String text) {
                if (!text.equals(textView.getText().toString())) {
                    textView.setText(text);
                }
                TLog.d("被动刷新：" + text);
            }
        });
    }
}
